//
//  SetData.m
//  OST
//
//  Created by mac on 13-7-11.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#import "SceneData.h"
#import "Common.h"

@interface SceneData ()

@end

@implementation SceneData

@synthesize resultData;

static SceneData *sharSceneDataInstance = nil;

+(SceneData *) sharedInstance
{
    if (!sharSceneDataInstance) {
        sharSceneDataInstance = [[SceneData alloc]init];
    }
    return sharSceneDataInstance;
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSArray *setStrs= [reciveData componentsSeparatedByString:@"/@/" ];
    NSMutableArray *result = [NSMutableArray array];
    for (NSString *set in setStrs) {
        if ([set length]>0) {
            NSArray *items = [set componentsSeparatedByString:@"/./"];
            if ([items count]>0) {
                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                [dict setValue:[items objectAtIndex:0] forKey:@"name" ];
                [dict setValue:set forKey:@"value" ];
                [result addObject:dict];
            }
        }
    }
    self.resultData = result;
    [self doneLoadData:resultData];
}

-(void)cleanData
{
    resultData=nil;
}

-(void)reLoadData
{
    self.httpRequest = [Common createHTTPRequest:@"cgi-bin/getDB.cgi?TN=scene&R=0" delegate:self];
    [self.httpRequest startAsynchronous];
}

-(id)getResultData
{
    return resultData;
}

- (void)newScene:(NSString *)sceneName {
    self.httpRequest = [Common createHTTPRequest:[NSString stringWithFormat:@"cgi-bin/Scene.cgi?action=do_create&label=%@",sceneName] delegate:self];
    [self.httpRequest startAsynchronous];
}

@end
